home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
language
/
nasm20
/
nasm20s.zoo
/
lexer.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-01-22
|
34KB
|
1,273 lines
/* ---------------------------------------------------------------------- */
/* Copyright (C) 1991 by Natürlich! */
/* This file is copyrighted! */
/* Refer to the documentation for details. */
/* ---------------------------------------------------------------------- */
#define DEBUG 0
#define TOKDEBUG 0 /* following set 4 Atari 8MHz */
#define FINPUT_IO 1 /* yields 15% speed increase */
#define QINPUT_IO 1 /* yields 20% speed increase */
#define USEINLINE 0
#define QSTRING 0 /* 1 == doesn't do much */
#define QWHITE 1
#define QCOMMENT 1
#define QIDENT 1
#define QIDENT2 0 /* 1 == worsens performance ! */
#define QLABEL 0 /* 1 == doesn't do anything */
#define QMACRO 0 /* 1 == same or worse */
#define QDIRECT 0 /* 1 == doesn't do anything */
/* --------------------------------------------------------- */
/* SHIT!! FLEX can't digest characters >= 128 */
/* Now I have to write my own lexer... */
/* --------------------------------------------------------- */
#include "defines.h"
#include "nasm.h"
#include "y_tab.h"
#include <stdio.h>
#if OS == TOS
#include <osbind.h>
#endif
#include <setjmp.h>
#include "debug.h"
#include "code.h"
#include NMALLOC_H
#if VERSION && FINPUT_IO
extern buffer huge *bp;
# include "inputfst.h"
#endif
#define LINESTART 0
#define INSTRUCTION 1
#define AFTERINSTR 2
#define AFTERELSE 3
#define AFTEROPTION 4
#define AFTERFLOAT 5
#define AFTERINCLUDE 6
#define COMMENT 7
#define E_GARBAGE garbage /* historic */
#define E_LABELFORM labelform
#define E_HEXLEN hexlen
#define E_INTSIZE intsize
static char
igarbage[] = "Garbage in the instruction field",
garbage[] = "Totally uncomprehendable garbage",
labelform[] = "Label starts off with wrong character",
hexlen[] = "Hex value exceeds 16 Bit (not that good on a 64K machine)",
intsize[] = "Integer value >= 65536, how would that fit into 2 bytes ?",
mpara_incomplete[] =
"Incomplete macro parameter (form %[$]<[0-9]+|(<label>))";
/* --------------------------------------------------------- */
/* The ultra-clever (har har) way of deciding whether we are */
/* facing something usable as an identifier character. */
/* There is a method to this madness: */
/* Bit7 . Bit6 . Bit5 . Bit4 . Bit3 . Bit2 . Bit1 . Bit0 */
/* -----+------+------+------+------+------+------+----- */
/* Lower| | | Foo | A-Z |Float | Hex | No */
/* -----+------+------+------+------+------+------+----- */
/* $80 $40 $20 $10 $08 $04 $02 $01 */
/* */
/* A question remains, are we losing with this table ?? */
/* --------------------------------------------------------- */
#define is_ident( c) (is_what[ (c)])
#define is_lower( c) ((signed char) is_what[ (c)] < 0)
#define is_hex( c) (is_what[ (c)] & M_HEX)
#define is_digit( c) (is_what[ (c)] == DIGIT)
#define is_letter( c) (is_what[ (c)] & M_LETTER)
#define is_float( c) (is_what[ (c)] & M_FLOAT)
#define tis_ident( c) (p_table[ (c)])
#define tis_lower( c) ((signed char) p_table[ (c)] < 0)
#define tis_hex( c) (p_table[ (c)] & M_HEX)
#define tis_digit( c) (p_table[ (c)] == DIGIT)
#define tis_letter( c) (p_table[ (c)] & M_LETTER)
#define tis_float( c) (p_table[ (c)] & M_FLOAT)
#define M_LOWER 0x80
#define M_FOO 0x10
#define M_LETTER 0x08
#define M_FLOAT 0x04
#define M_HEX 0x02
#define M_DIGIT 0x01
#define DIGIT (M_DIGIT | M_HEX | M_FLOAT)
#define L (M_LETTER | M_LOWER) /* lower */
#define A M_LETTER /* upper */
#define H (M_LETTER | M_HEX) /* up&hex */
#define E (M_LETTER | M_HEX | M_FLOAT)
#define P M_FLOAT
#define X M_FOO
#define N DIGIT
byte is_what[] = /* xlat: is' watt !?!? */
{
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $00 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $10 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,P,0, /* $20 */
N,N,N,N, N,N,N,N, N,N,X,0, 0,0,0,X, /* $30 */
X,H,H,H, H,E,H,A, A,A,A,A, A,A,A,A, /* $40 */
A,A,A,A, A,A,A,A, A,A,A,0, 0,0,0,X, /* $50 */
0,L,L,L, L,L,L,L, L,L,L,L, L,L,L,L, /* $60 */
L,L,L,L, L,L,L,L, L,L,L,0, 0,0,0,0, /* $70 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $80 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $90 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $A0 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $B0 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $C0 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $D0 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $E0 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 /* $F0 */
};
#undef F
#undef N
#undef L
#undef A
#undef H
#undef E
#undef P
#undef X
#define is_white( c) (white[ (c)])
#define skip_white(c) while( white[ c]) c = uinput()
#define tis_white( c) (p_table[ (c)])
#define tskip_white(c) while( p_table[ c]) c = uinput()
static char white[] = /* ain't no saying whether this actually */
{ /* helps improve the speed */
0,0,0,0, 0,0,0,0, 0,1,0,0, 0,1,0,0, /* $00 */
0,0,0,0, 0,0,0,0, 0,0,1,0, 0,0,0,0, /* $10 */ /* $1A for MSDOS */
1,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $20 */ /* whatever that */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $30 */ /* might be */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $40 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $50 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $60 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $70 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $80 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $90 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $A0 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $B0 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $C0 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $D0 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $E0 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 /* $F0 */
};
#define A 0x01 /* 'X' */
#define B 0x02 /* 'Y' */
#define C 0x03 /* '#' */
#define D 0x04 /* '(' */
#define E 0x05 /* ')' */
#define F 0x06 /* ',' */
#define G 0x07 /* '=' */
#define H 0x08 /* '+' */
#define I 0x09 /* '-' */
#define J 0x0A /* '!' */
#define K 0x0B /* '&' */
#define L 0x0C /* '*' */
#define M 0x0D /* '/' */
#define N 0x0E /* '\\' */
#define O 0x0F /* '^' */
#define P 0x10 /* '[' */
#define Q 0x11 /* ']' */
#define IREGS 0x02
static byte af1_toks[] =
{
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $00 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $10 */
0,J,0,C, 0,0,K,0, D,E,L,H, F,I,0,M, /* $20 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,G,0,0, /* $30 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $40 */
0,0,0,0, 0,0,0,0, A,B,0,P, N,Q,O,0, /* $50 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $60 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $70 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $80 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $90 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $A0 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $B0 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $C0 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $D0 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $E0 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 /* $F0 */
};
static byte af2_toks[] =
{
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $00 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $10 */
0,J,0,0, 0,0,K,0, D,E,L,H, F,I,0,M, /* $20 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,G,0,0, /* $30 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* $40 */
0,0,0,0, 0,0,0,0, 0,0,0,P, N,Q,O,0, /* $50 */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,